<?php
/**
 * 首页
 * @file    ItemsControl.class.php
 * @author  kelecode@gmail.com
 * @date    2013-11-23
 * modify
 */
class ItemsControl extends Control{

    public function __construct(){
        parent::__construct();
    }

    public function index(){
		$cid = (int)getgpc('cid');
		$order = (int)getgpc('order');
		$order = $order == 1 ? 'ctime' : 'sort';
		$pageSize = 27;
		$categories = M('items', 'items')->categoryList();
        $items = M('items', 'items')->itemList($order,$cid,$pageSize);
		$totalRows = $items['count'];
		$itemList = $items['lists'];
		foreach($itemList as $key => $val){
			$itemList[$key]['sub_name'] = tinySubstr($val['name'],0,8);
			$itemList[$key]['cname'] = $categories[$val['cid']];
			$itemList[$key]['qrcode'] = '';
			$itemList[$key]['ctime'] = date('m月d日 H:i',$val['ctime']);
			$itemList[$key]['description'] = empty($val['description']) ? '精选美味，尽在零食宝' : $val['description'];
		}

		$tmpl = '';
		$tinyPage = new TinyPage($totalRows,$pageSize,$tmpl);
		$page = $tinyPage->show();

        $this->assign('title','lingshibao');
		$this->assign('current_cid',$cid);
		$this->assign('order',$order);
        $this->assign('itemList',$itemList);
		$this->assign('categories',$categories);
		$this->assign('page',$page);
        $this->display('index', 'com.items.index');
    }

}